package com.fuxi.cloud.desreport.service.a;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;

import com.fuxi.cloud.desreport.render.handler.convert.ApiDataConvertAdapter;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.fuxi.cloud.api.data.IDataSetFactory;
import com.fuxi.cloud.common.constant.CommonConstant;
import com.fuxi.cloud.common.constant.JmConst;
import com.fuxi.cloud.common.util.CommonUtils;
import com.fuxi.cloud.common.util.oConvertUtils;
import com.fuxi.cloud.common.vo.JmDictModel;
import com.fuxi.cloud.common.vo.Result;
import com.fuxi.cloud.config.client.JmReportTokenClient;
import com.fuxi.cloud.desreport.b.c;
import com.fuxi.cloud.desreport.dao.JimuReportDao;
import com.fuxi.cloud.desreport.dao.JimuReportDbDao;
import com.fuxi.cloud.desreport.dao.JimuReportDbFieldDao;
import com.fuxi.cloud.desreport.dao.JimuReportDbParamDao;
import com.fuxi.cloud.desreport.entity.JimuReport;
import com.fuxi.cloud.desreport.entity.JmReportDb;
import com.fuxi.cloud.desreport.entity.JmReportDbField;
import com.fuxi.cloud.desreport.entity.JmReportDbParam;
import com.fuxi.cloud.desreport.model.JmExpBacker;
import com.fuxi.cloud.desreport.model.JmExpression;
import com.fuxi.cloud.desreport.model.JmPage;
import com.fuxi.cloud.desreport.model.MergedResult;
import com.fuxi.cloud.desreport.model.QueryVO;
import com.fuxi.cloud.desreport.model.RenderInfo;
import com.fuxi.cloud.desreport.model.ReportDbInfo;
import com.fuxi.cloud.desreport.render.a.ar.b;
import com.fuxi.cloud.desreport.render.handler.BaseRenderHandler;
import com.fuxi.cloud.desreport.render.utils.FreeMarkerUtils;
import com.fuxi.cloud.desreport.render.utils.RegexMatches;
import com.fuxi.cloud.desreport.render.utils.ReportUtil;
import com.fuxi.cloud.desreport.service.IJimuReportDictService;
import com.fuxi.cloud.desreport.service.IJimuReportService;
import com.fuxi.cloud.desreport.service.IJmReportDbFieldService;
import com.fuxi.cloud.dyndb.JmreportDynamicDbUtil;
import com.fuxi.cloud.dyndb.util.JmreportSqlUtils;
import org.jeecgframework.minidao.pojo.MiniDaoPage;
import org.jeecgframework.minidao.util.SnowflakeIdWorker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;

@Service("jimuReportServiceImpl")
public class d implements IJimuReportService {
    private static final Logger a = LoggerFactory.getLogger(d.class);

    @Autowired
    private JimuReportDbDao reportDbDao;

    @Autowired
    private JimuReportDbParamDao dbParamDao;

    @Autowired
    private JimuReportDao reportDao;

    @Autowired
    private JimuReportDbFieldDao dbFieldDao;

    @Autowired
    private JmreportDynamicDbUtil jmreportDynamicDbUtil;

    @Autowired
    private IJimuReportDictService dictService;

    @Autowired
    private IJmReportDbFieldService jmReportDbFieldService;

    @Autowired
    private JmReportTokenClient jimuTokenClient;

    @Autowired
    Map<String, BaseRenderHandler> renderHandlerMap;

    @Autowired(required = false)
    private ApiDataConvertAdapter apiDataConverAdapter;

    @Override
    public Map<String, Object> getDataById(String id, JSONObject paramJson, boolean onlyPageData, String username) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        JimuReport jimuReport = this.reportDao.get(id);
        if (jimuReport == null)
            return (Map)hashMap;
        List<JmReportDb> list = this.reportDbDao.selectList(id);
        if (list == null)
            return (Map)hashMap;
        String str1 = "";
        JSONObject jSONObject = JSONObject.parseObject(jimuReport.getJsonStr());
        JSONArray jSONArray = null;
        ArrayList<JmExpression> arrayList = new ArrayList();
        if (jSONObject != null) {
            if (jSONObject.containsKey("groupField") && jSONObject.containsKey("isGroup"))
                str1 = jSONObject.getString("groupField");
            jSONArray = jSONObject.getJSONArray("dbexps");
        }
        if (jSONArray != null && jSONArray.size() > 0)
            for (byte b = 0; b < jSONArray.size(); b++) {
                String str = jSONArray.getString(b);
                JmExpression jmExpression = new JmExpression(str);
                arrayList.add(jmExpression);
            }
        String str2 = paramJson.getString("printAll");
        for (JmReportDb jmReportDb : list) {
            if (onlyPageData && !"1".equals(jmReportDb.getIsPage()))
                continue;
            String str3 = jmReportDb.getDbCode();
            String str4 = jmReportDb.getDbSourceType();
            JSONObject jSONObject1 = new JSONObject();
            if ("2".equals(jmReportDb.getDbType())) {
                ReportDbInfo reportDbInfo = a(jmReportDb, paramJson, username);
                hashMap.put(str3, reportDbInfo);
            }
            if ("0".equals(jmReportDb.getDbType())) {
                String str5 = getBaseSql(jmReportDb.getId(), jmReportDb.getDbDynSql(), paramJson);
                String str6 = a(jmReportDb, paramJson);
                a(jmReportDb, str5, str6, arrayList);
                String str7 = null;
                if (oConvertUtils.isNotEmpty(str1)) {
                    String[] arrayOfString = str1.split(".");
                    if (arrayOfString.length == 2 &&
                            str3.equals(arrayOfString[0]))
                        str7 = arrayOfString[1];
                }
                String str8 = a(str5, str6, str7);
                a.info("------+ str3 + "+ str8);
                String str9 = jmReportDb.getDbSource();
                Integer integer1 = Integer.valueOf(oConvertUtils.getInt(paramJson.get("pageSize"), 10));
                Integer integer2 = Integer.valueOf(oConvertUtils.getInt(paramJson.get("pageNo"), 1));
                if (oConvertUtils.isNotEmpty(str9)) {
                    if (oConvertUtils.isNotEmpty(str2)) {
                        ReportDbInfo reportDbInfo1 = new ReportDbInfo();
                        List list2 = this.jmreportDynamicDbUtil.findList(jmReportDb.getDbSource(), str8, new Object[0]);
                        if (ObjectUtil.isNotEmpty(list2))
                            list2 = ReportUtil.a(list2);
                        reportDbInfo1.setList(list2);
                        hashMap.put(str3, reportDbInfo1);
                    } else {
                        String str = JmreportSqlUtils.getCountSql(str8);
                        Map map1 = (Map)this.jmreportDynamicDbUtil.findOne(jmReportDb.getDbSource(), str, new Object[0]);
                        int i = 1;
                        Object object = map1.get("total");
                        int j = 0;
                        if (object != null) {
                            j = Integer.parseInt(object.toString());
                            double d1 = Double.parseDouble(object.toString()) / integer1.intValue();
                            i = (int)Math.ceil(d1);
                        }
                        List list2 = null;
                        if ("1".equals(jmReportDb.getIsPage())) {
                            String str10 = JmreportSqlUtils.createPageSqlByDBType(str4, str8, integer2.intValue(), integer1.intValue());
                            list2 = this.jmreportDynamicDbUtil.findList(jmReportDb.getDbSource(), str10, new Object[0]);
                        } else {
                            list2 = this.jmreportDynamicDbUtil.findList(jmReportDb.getDbSource(), str8, new Object[0]);
                        }
                        ReportDbInfo reportDbInfo1 = new ReportDbInfo(i, j, jmReportDb.getIsPage(), jmReportDb.getIsList(), jmReportDb.getDbType());
                        if (ObjectUtil.isNotEmpty(list2))
                            list2 = ReportUtil.a(list2);
                        reportDbInfo1.setList(list2);
                        hashMap.put(str3, reportDbInfo1);
                    }
                } else if (ObjectUtil.isNotEmpty(str2)) {
                    ReportDbInfo reportDbInfo1 = new ReportDbInfo();
                    List list2 = this.reportDbDao.selectListBySql(str8);
                    if (ObjectUtil.isNotEmpty(list2))
                        list2 = ReportUtil.a(list2);
                    reportDbInfo1.setList(list2);
                    hashMap.put(str3, reportDbInfo1);
                } else {
                    String str10 = jmReportDb.getIsPage();
                    String str11 = jmReportDb.getIsList();
                    if ("0".equals(str10) || ObjectUtil.isEmpty(str10))
                        integer2 = Integer.valueOf(1);
                    ReportDbInfo reportDbInfo1 = null;
                    if ("1".equals(str10)) {
                        MiniDaoPage miniDaoPage = this.reportDbDao.selectPageBySql(str8, integer2.intValue(), integer1.intValue());
                        reportDbInfo1 = new ReportDbInfo(miniDaoPage.getPages(), miniDaoPage.getTotal(), str10, str11, jmReportDb.getDbType());
                        List list2 = miniDaoPage.getResults();
                        if (ObjectUtil.isNotEmpty(list2))
                            list2 = ReportUtil.a(list2);
                        reportDbInfo1.setList(list2);
                    } else {
                        List list2 = this.reportDbDao.selectListBySql(str8);
                        if (list2 != null) {
                            reportDbInfo1 = new ReportDbInfo(1L, list2.size(), str10, str11, jmReportDb.getDbType());
                            if (ObjectUtil.isNotEmpty(list2))
                                list2 = ReportUtil.a(list2);
                            reportDbInfo1.setList(list2);
                        }
                    }
                    hashMap.put(str3, reportDbInfo1);
                }
                ReportDbInfo reportDbInfo = (ReportDbInfo)hashMap.get(str3);
                List<Map<String, Object>> list1 = reportDbInfo.getList();
                replaceDbCode(jmReportDb.getId(), username, list1);
                reportDbInfo.setList(list1);
                hashMap.replace(str3, reportDbInfo);
            }
            if ("1".equals(jmReportDb.getDbType())) {
                String str5 = jmReportDb.getApiUrl();
                if (str5.contains("?")) {
                    List<JmReportDbParam> list1 = this.dbParamDao.list(jmReportDb.getId());
                    if (c.a(list1))
                        for (JmReportDbParam jmReportDbParam : list1) {
                            jSONObject1.put(jmReportDbParam.getParamName(), jmReportDbParam.getParamValue());
                        }
                }
                JSONObject jSONObject2 = new JSONObject();
                Iterator<String> iterator1 = paramJson.keySet().iterator();
                while (iterator1.hasNext()) {
                    String str = iterator1.next();
                    if (str.contains(str3))
                        str = str.replace(str3 + "__", "");
                    if (jSONObject1.containsKey(str))
                        jSONObject1.remove(str);
                }
                jSONObject2.putAll((Map)paramJson);
                jSONObject2.putAll((Map)jSONObject1);
                Iterator<String> iterator2 = jSONObject2.keySet().iterator();
                JSONObject jSONObject3 = new JSONObject();
                while (iterator2.hasNext()) {
                    String str7 = iterator2.next();
                    String str8 = jSONObject2.getString(str7);
                    if (ObjectUtil.isEmpty(str8))
                        str8 = "";
                    if (str7.contains(str3))
                        str7 = str7.replace(str3 + "__", "");
                    if (str5.indexOf(str7) > 0) {
                        str5 = str5.replace(str7 + "='${" + str7 + "}'", str7 + "=" + str8);
                        continue;
                    }
                    jSONObject3.put(str7, str8);
                }
                if (ObjectUtil.isNotEmpty(str2))
                    if (str5.contains("?")) {
                        str5 = str5 + "&printAll=true";
                    } else {
                        str5 = str5 + "?printAll=true";
                    }
                if (ObjectUtil.isNotEmpty(str1))
                    if (str5.contains("?")) {
                        str5 = str5 + "&groupField=" + str1;
                    } else {
                        str5 = str5 + "?groupField=" + str1;
                    }
                jmReportDb.setApiUrl(str5);
                String str6 = paramJson.getString("X-Access-Token");
                Map map1 = a(jmReportDb, str6, jSONObject3);
                ReportDbInfo reportDbInfo = new ReportDbInfo(jmReportDb.getIsPage(), jmReportDb.getIsList(), jmReportDb.getDbType());
                Object object = map1.get("dataList");
                if (ObjectUtil.isNotEmpty(object))
                    reportDbInfo.setList((List)object);
                if (ObjectUtil.isEmpty(str2)) {
                    Object object1 = map1.get("linkList");
                    if (ObjectUtil.isNotEmpty(object1))
                        reportDbInfo.setLinkList((List)object1);
                    reportDbInfo.setTotal(CommonUtils.getLong(map1.get("total"), Long.valueOf(0L)).longValue());
                    reportDbInfo.setCount(CommonUtils.getLong(map1.get("count"), Long.valueOf(0L)).longValue());
                }
                if (null != reportDbInfo.getList()) {
                    List<Map<String, Object>> list1 = reportDbInfo.getList();
                    replaceDbCode(jmReportDb.getId(), username, list1);
                    reportDbInfo.setList(list1);
                }
                hashMap.put(str3, reportDbInfo);
            }
        }
        Map map = JmExpression.getExpMapByList(arrayList);
        hashMap.put("expData", map);
        return (Map)hashMap;
    }

    @Override
    public Map importExcel(MultipartFile file) throws IOException {
//        InputStream var2 = file.getInputStream();
//        XSSFWorkbook var3 = new XSSFWorkbook(var2);
//        Sheet var4 = var3.getSheetAt(0);
//        IdentityHashMap var5 = new IdentityHashMap();
//        ArrayList var6 = new ArrayList();
//        IdentityHashMap var7 = new IdentityHashMap();
//        ArrayList var8 = new ArrayList();
//        ArrayList var9 = new ArrayList();
//        HashMap var10 = new HashMap();
//        int var11 = 0;
//        Iterator var12 = var4.iterator();
//
//        while(var12.hasNext()) {
//            Row var13 = (Row)var12.next();
//            int var14 = var13.getRowNum();
//            IdentityHashMap var15 = new IdentityHashMap();
//            IdentityHashMap var16 = new IdentityHashMap();
//            Iterator var17 = var13.iterator();
//
//            while(var17.hasNext()) {
//                Cell var18 = (Cell)var17.next();
//                var18.setCellType(CellType.STRING);
//                IdentityHashMap var19 = new IdentityHashMap();
//                IdentityHashMap var20 = new IdentityHashMap();
//                int var21;
//                MergedResult var22;
//                int[] var23;
//                Map var25;
//                if (var18.getCellTypeEnum() != CellType.BLANK) {
//                    switch(null.a[var18.getCellTypeEnum().ordinal()]) {
//                        case 1:
//                            if (StringUtils.isNotEmpty(var18.getRichStringCellValue().getString())) {
//                                var19.put("text", var18.getRichStringCellValue().getString());
//                            }
//                            break;
//                        case 2:
//                            if (DateUtil.isCellDateFormatted(var18)) {
//                                var19.put("text", var18.getRichStringCellValue());
//                            } else {
//                                var19.put("text", var18.getNumericCellValue());
//                            }
//                            break;
//                        case 3:
//                            var19.put("text", var18.getRichStringCellValue());
//                    }
//
//                    var21 = var18.getColumnIndex();
//                    var22 = this.a(var4, var14, var21, var8);
//                    if (var22.isMerged()) {
//                        var23 = new int[0];
//                        var23 = new int[]{var22.getEndRow() - var22.getStartRow(), var22.getEndCol() - var22.getStartCol()};
//                        String var24 = var22.getEndRow() + "," + var22.getStartRow() + "," + var22.getEndCol() + "," + var22.getStartCol();
//                        if (!var9.contains(var24)) {
//                            var19.put("merge", var23);
//                            var9.add(var24);
//                        }
//                    }
//
//                    var25 = this.a(var18, var22.isMerged());
//                    var6.add(var25);
//                    var20.put("width", (int)var4.getColumnWidthInPixels(var21));
//                    var10.put(var21, var20);
//                    var19.put("style", var11);
//                    var16.put(var21, var19);
//                    var19.put("height", (double)var13.getHeightInPoints() + 9.5D);
//                    ++var11;
//                } else {
//                    var21 = var18.getColumnIndex();
//                    var22 = this.a(var4, var14, var21, var8);
//                    if (var22.isMerged()) {
//                        var23 = new int[0];
//                        var23 = new int[]{var22.getEndRow() - var22.getStartRow(), var22.getEndCol() - var22.getStartCol()};
//                        if (!var9.contains(var23[0] + "," + var23[1])) {
//                            var19.put("merge", var23);
//                            var9.add(var23[0] + "," + var23[1]);
//                        }
//                    }
//
//                    if (!var22.isMerged()) {
//                        var25 = this.a(var18, var22.isMerged());
//                        var6.add(var25);
//                        var19.put("styles", var11);
//                        var16.put(var21, var19);
//                        var19.put("height", (double)var13.getHeightInPoints() + 9.5D);
//                        ++var11;
//                    }
//                }
//
//                var5.put("styles", var6);
//                var15.put("cells", var16);
//            }
//
//            var7.put(var14, var15);
//            var5.put("rows", var7);
//            var5.put("merges", var8);
//            var5.put("cols", var10);
//        }
//
//        return var5;
        return null;
    }

    private Map<String, Object> a(Cell paramCell, boolean paramBoolean) {
        XSSFCellStyle xSSFCellStyle = (XSSFCellStyle)paramCell.getCellStyle();
        HashMap<Object, Object> hashMap1 = new HashMap<>();
        HashMap<Object, Object> hashMap2 = new HashMap<>();
        HashMap<Object, Object> hashMap3 = new HashMap<>();
        if (((XSSFCell)paramCell).getCellStyle().getFont().getBold())
            hashMap3.put("bold", Boolean.valueOf(true));
        hashMap3.put("size", Short.valueOf(((XSSFCell)paramCell).getCellStyle().getFont().getFontHeightInPoints()));
        if (xSSFCellStyle.getBorderBottomEnum() == BorderStyle.THIN) {
            XSSFColor xSSFColor1 = xSSFCellStyle.getBottomBorderXSSFColor();
            String str = a(xSSFColor1);
            String[] arrayOfString = { "thin", str };
            hashMap2.put("bottom", arrayOfString);
        }
        if (xSSFCellStyle.getBorderLeftEnum() == BorderStyle.THIN) {
            XSSFColor xSSFColor1 = xSSFCellStyle.getLeftBorderXSSFColor();
            String str = a(xSSFColor1);
            String[] arrayOfString = { "thin", str };
            hashMap2.put("left", arrayOfString);
        }
        if (xSSFCellStyle.getBorderRightEnum() == BorderStyle.THIN) {
            XSSFColor xSSFColor1 = xSSFCellStyle.getLeftBorderXSSFColor();
            String str = a(xSSFColor1);
            String[] arrayOfString = { "thin", str };
            hashMap2.put("right", arrayOfString);
        }
        if (xSSFCellStyle.getBorderTopEnum() == BorderStyle.THIN) {
            XSSFColor xSSFColor1 = xSSFCellStyle.getLeftBorderXSSFColor();
            String str = a(xSSFColor1);
            String[] arrayOfString = { "thin", str };
            hashMap2.put("top", arrayOfString);
        }
        if (xSSFCellStyle.getAlignmentEnum() == HorizontalAlignment.CENTER)
            hashMap1.put("align", "center");
        if (xSSFCellStyle.getBorderBottomEnum() == BorderStyle.THIN && xSSFCellStyle.getBorderLeftEnum() == BorderStyle.THIN && xSSFCellStyle.getBorderTopEnum() == BorderStyle.THIN && paramBoolean == true) {
            XSSFColor xSSFColor1 = xSSFCellStyle.getLeftBorderXSSFColor();
            String str = a(xSSFColor1);
            String[] arrayOfString = { "thin", str };
            hashMap2.put("right", arrayOfString);
        }
        if (xSSFCellStyle.getBorderRightEnum() != BorderStyle.NONE || xSSFCellStyle.getBorderBottomEnum() != BorderStyle.NONE || xSSFCellStyle.getBorderLeftEnum() != BorderStyle.NONE || xSSFCellStyle.getBorderTopEnum() != BorderStyle.NONE)
            hashMap1.put("border", hashMap2);
        XSSFFont xSSFFont = ((XSSFCell)paramCell).getCellStyle().getFont();
        if (xSSFFont.getXSSFColor() != null) {
            XSSFColor xSSFColor1 = xSSFFont.getXSSFColor();
            byte[] arrayOfByte = xSSFColor1.getRGB();
            if (arrayOfByte.length > 3) {
                String str = String.format("#%02X%02X%02X", new Object[] { Byte.valueOf(arrayOfByte[0]), Byte.valueOf(arrayOfByte[1]), Byte.valueOf(arrayOfByte[2]) });
                hashMap1.put("color", str);
            }
        }
        XSSFColor xSSFColor = xSSFCellStyle.getFillBackgroundXSSFColor();
        short s = xSSFCellStyle.getFillBackgroundColor();
        if (null != xSSFColor) {
            byte[] arrayOfByte = xSSFColor.getRGB();
            if (null != arrayOfByte) {
                String str1 = "#" + String.format("%02X", new Object[] { Byte.valueOf(arrayOfByte[0]) }) + String.format("%02X", new Object[] { Byte.valueOf(arrayOfByte[1]) }) + String.format("%02X", new Object[] { Byte.valueOf(arrayOfByte[2]) });
                String str2 = a(xSSFColor);
                hashMap1.put("bgcolor", str2);
            }
        }
        hashMap1.put("font", hashMap3);
        return (Map)hashMap1;
    }

    public String a(XSSFColor paramXSSFColor) {
        if (paramXSSFColor != null) {
            byte[] arrayOfByte = paramXSSFColor.getRGB();
            if (null != arrayOfByte)
                return "#" + String.format("%02X", new Object[] { Byte.valueOf(arrayOfByte[0]) }) + String.format("%02X", new Object[] { Byte.valueOf(arrayOfByte[1]) }) + String.format("%02X", new Object[] { Byte.valueOf(arrayOfByte[2]) });
            return "#000000";
        }
        return "#000000";
    }

    @Override
    public boolean excelQueryName(JimuReport design) {
        boolean bool = false;
        Integer integer = Integer.valueOf(0);
        if (ObjectUtil.isNotEmpty(design.getId())) {
            JimuReport jimuReport = this.reportDao.get(design.getId());
            if (null != jimuReport && jimuReport.getName() != null) {
                if (!jimuReport.getName().equals(design.getName())) {
                    integer = this.reportDao.excelQueryName(design.getName());
                    if (integer.intValue() == 0)
                        bool = true;
                } else {
                    bool = true;
                }
            } else {
                integer = this.reportDao.excelQueryName(design.getName());
                if (integer.intValue() == 0)
                    bool = true;
            }
        } else {
            integer = this.reportDao.excelQueryName(design.getName());
            if (integer.intValue() == 0)
                bool = true;
        }
        return bool;
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void reportCopy(JimuReport report) {
        JimuReport var2 = this.reportDao.get(report.getId());
        if (var2 != null) {
            var2.setId(String.valueOf(SnowflakeIdWorker.generateId()));
            String var3 = String.format("%04d", (new Random()).nextInt(9999));
            String var4 = "";
            String var5 = "";
            if (var2.getName().indexOf("副本") == -1) {
                var4 = var2.getCode() + var3;
                var5 = var2.getName() + "副本" + var3;
            } else {
                var4 = var2.getCode().substring(0, 14) + var3;
                var5 = var2.getName().substring(0, var2.getName().indexOf("副本")) + "副本" + var3;
            }

            var2.setName(var5);
            var2.setCode(var4);
            var2.setTemplate(0);
            var2.setCreateBy(report.getCreateBy());
            var2.setCreateTime(report.getCreateTime());
            var2.setViewCount(0L);
            var2.setUpdateTime((Date)null);
            var2.setUpdateBy((String)null);
            this.reportDao.insert(var2);
        }

        List var10 = this.reportDbDao.selectList(report.getId());
        if (var10.size() > 0) {
            Iterator var11 = var10.iterator();

            while(true) {
                List var7;
                Iterator var8;
                JmReportDb var12;
                do {
                    if (!var11.hasNext()) {
                        return;
                    }

                    var12 = (JmReportDb)var11.next();
                    List var6 = this.dbFieldDao.listByDbId(var12.getId());
                    var7 = this.dbParamDao.list(var12.getId());
                    var12.setId(String.valueOf(SnowflakeIdWorker.generateId()));
                    var12.setJimuReportId(var2.getId());
                    this.reportDbDao.insert(var12);
                    if (var6.size() > 0) {
                        var8 = var6.iterator();

                        while(var8.hasNext()) {
                            JmReportDbField var9 = (JmReportDbField)var8.next();
                            var9.setId(String.valueOf(SnowflakeIdWorker.generateId()));
                            var9.setJimuReportDbId(var12.getId());
                            this.dbFieldDao.insert(var9);
                        }
                    }
                } while(var7.size() <= 0);

                var8 = var7.iterator();

                while(var8.hasNext()) {
                    JmReportDbParam var13 = (JmReportDbParam)var8.next();
                    var13.setId(String.valueOf(SnowflakeIdWorker.generateId()));
                    var13.setJimuReportHeadId(var12.getId());
                    this.dbParamDao.insert(var13);
                }
            }
        }
    }

    private MergedResult a(Sheet paramSheet, int paramInt1, int paramInt2, List<String> paramList) {
        int i = paramSheet.getNumMergedRegions();
        for (byte b = 0; b < i; b++) {
            CellRangeAddress cellRangeAddress = paramSheet.getMergedRegion(b);
            int j = cellRangeAddress.getFirstColumn();
            int k = cellRangeAddress.getLastColumn();
            int m = cellRangeAddress.getFirstRow();
            int n = cellRangeAddress.getLastRow();
            if (paramInt1 >= m && paramInt1 <= n &&
                    paramInt2 >= j && paramInt2 <= k) {
                String str = cellRangeAddress.formatAsString();
                if (!paramList.contains(str))
                    paramList.add(str);
                return new MergedResult(true, m, n, j, k);
            }
        }
        return new MergedResult(false, 0, 0, 0, 0);
    }

    private Map a(JmReportDb paramJmReportDb, String paramString, JSONObject paramJSONObject) {
        String str1 = paramJmReportDb.getApiUrl();
        Map map = new HashMap<>();
        if (StringUtils.isNotEmpty(paramString))
            map = this.jimuTokenClient.getUserInfo(paramString);
        str1 = c.c(str1, map);
        String str2 = "";
        if ("0".equals(paramJmReportDb.getApiMethod())) {
            Iterator<String> iterator = paramJSONObject.keySet().iterator();
            while (iterator.hasNext()) {
                String str3 = iterator.next();
                String str4 = paramJSONObject.getString(str3);
                if (str1.indexOf(str3 + "=") < 0) {
                    if (str1.indexOf("?") > 0) {
                        str1 = str1 + "&" + str3 + "=" + str4;
                        continue;
                    }
                    str1 = str1 + "?" + str3 + "=" + str4;
                }
            }
            str2 = c.b(str1, paramString);
        } else {
            str2 = c.a(str1, paramString, paramJSONObject);
        }
        HashMap<Object, Object> hashMap = new HashMap<>();
        try {
            JSONObject jSONObject = RegexMatches.e(str2);
            String str3 = "";
            String str4 = "";
            String str5 = "";
            String str6 = "";
            if (ObjectUtil.isEmpty(this.apiDataConverAdapter)) {
                if (jSONObject.containsKey("data"))
                    str3 = jSONObject.get("data").toString();
                if (jSONObject.containsKey("links"))
                    str4 = jSONObject.get("links").toString();
                if (jSONObject.containsKey("total"))
                    if (jSONObject.get("total") != null) {
                        str5 = jSONObject.get("total").toString();
                    } else {
                        str5 = "0";
                    }
                if (jSONObject.containsKey("count"))
                    if (jSONObject.get("count") != null) {
                        str6 = jSONObject.get("count").toString();
                    } else {
                        str6 = "0";
                    }
            } else {
                str3 = this.apiDataConverAdapter.getData(jSONObject);
                str4 = this.apiDataConverAdapter.getLinks(jSONObject);
                str5 = this.apiDataConverAdapter.getTotal(jSONObject);
                str6 = this.apiDataConverAdapter.getCount(jSONObject);
            }
            List list1 = (List)JSONArray.parseObject(str3, List.class);
            List list2 = (List)JSONArray.parseObject(str4, List.class);
            hashMap.put("dataList", list1);
            hashMap.put("linkList", list2);
            hashMap.put("total", str5);
            hashMap.put("count", str6);
        } catch (Exception exception) {}
        return hashMap;
    }

    private String a(JmReportDb paramJmReportDb, Map<String, String[]> paramMap) {
        String str = paramJmReportDb.getDbDynSql().replace("\n", " ");
        boolean bool = str.contains("$");
        if (bool) {
            List<JmReportDbParam> list = this.dbParamDao.list(paramJmReportDb.getId());
            if (paramMap.size() > 0 && !paramMap.isEmpty()) {
                for (String str1 : paramMap.keySet()) {
                    String str2 = StringUtils.join((Object[])paramMap.get(str1));
                    str = str.replace("${" + str1 + "}", str2);
                }
            } else {
                for (JmReportDbParam jmReportDbParam : list)
                    str = str.replace("${" + jmReportDbParam.getParamName() + "}", jmReportDbParam.getParamValue());
            }
        }
        return str;
    }

    private JSONObject a(JSONObject var1, Map<String, String> var2) {
        JSONObject var3 = new JSONObject(true);
        var2.forEach((var2x, var3x) -> {
            var3.put(var3x, var1.get(var2x));
        });
        var2.forEach((var1x, var2x) -> {
            var1.remove(var1x);
        });
        Iterator var4 = var3.keySet().iterator();

        while(var4.hasNext()) {
            String var5 = (String)var4.next();
            var1.put(var5, var3.get(var5));
        }

        return var1;
    }

    private JSONObject a(JSONObject paramJSONObject) {
        ArrayList<Integer> arrayList = new ArrayList();
        Iterator<String> iterator = paramJSONObject.keySet().iterator();
        while (iterator.hasNext()) {
            String str = iterator.next();
            if (oConvertUtils.isNotEmpty(str) && !"NaN".equals(str))
                arrayList.add(Integer.valueOf(Integer.parseInt(str)));
        }
        Collections.sort(arrayList);
        JSONArray jSONArray = new JSONArray();
        JSONObject jSONObject = new JSONObject(true);
        for (Integer integer : arrayList) {
            JSONObject jSONObject1 = paramJSONObject.getJSONObject(String.valueOf(integer));
            jSONArray.add(jSONObject1);
            jSONObject.put(String.valueOf(integer), jSONObject1);
        }
        return jSONObject;
    }

    public static Map<String, Object> a(Map<String, Object> paramMap) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        if (paramMap == null || paramMap.isEmpty())
            return (Map)hashMap;
        Set<String> set = paramMap.keySet();
        for (String str1 : set) {
            String str2 = str1.toLowerCase();
            hashMap.put(str2, paramMap.get(str1));
        }
        return (Map)hashMap;
    }

    public static boolean a(Row paramRow) {
        if (paramRow == null)
            return true;
        for (short s = paramRow.getFirstCellNum(); s < paramRow.getLastCellNum(); s++) {
            Cell cell = paramRow.getCell(s);
            if (cell != null && cell.getCellTypeEnum() != CellType.BLANK)
                return false;
        }
        return true;
    }

    @Override
    public List<JmReportDbParam> queryReportParam(String reportId) {
        return this.reportDao.queryReportParam(reportId);
    }

    @Override
    public List<QueryVO> getReportQueryInfo(String id, String username) {
        ArrayList<QueryVO> arrayList = null;
        List<JmReportDb> list = this.reportDbDao.selectList(id);
        if (list != null && list.size() > 0) {
            arrayList = new ArrayList();
            HashSet<String> hashSet = new HashSet();
            ArrayList<String> arrayList1 = new ArrayList();
            for (JmReportDb jmReportDb : list) {
                String str1 = jmReportDb.getDbCode();
                String str2 = jmReportDb.getDbChName();
                List<JmReportDbField> list1 = this.dbFieldDao.listByDbId(jmReportDb.getId());
                if (list1 != null && list1.size() > 0)
                    for (JmReportDbField jmReportDbField : list1) {
                        if (jmReportDbField.getSearchFlag().equals(JmConst.FIELD_IS_QUERY)) {
                            String str3 = jmReportDbField.getFieldName();
                            if (arrayList1.contains(str3))
                                hashSet.add(str3);
                            arrayList1.add(str3);
                            String str4 = jmReportDbField.getFieldText();
                            String str5 = jmReportDbField.getWidgetType();
                            Integer integer = jmReportDbField.getSearchMode();
                            QueryVO queryVO = new QueryVO(str3, str4, str5, integer, str1, str2);
                            String str6 = jmReportDbField.getDictCode();
                            if (str6 != null && !"".equals(str6)) {
                                List<JmDictModel> list2 = null;
                                if (str6.contains("http")) {
                                    list2 = a(jmReportDbField);
                                } else if (str6.toLowerCase().indexOf("select") >= 0 && str6.toLowerCase().indexOf("from") >= 0) {
                                    list2 = this.reportDao.queryDictBySql(str6);
                                } else {
                                    list2 = this.dictService.queryDictItemsByCode(str6, username);
                                }
                                queryVO.setDictList(list2);
                            } else {
                                ArrayList arrayList2 = new ArrayList();
                                String str = jmReportDb.getDbDynSql();
                                if (oConvertUtils.isNotEmpty(str)) {
                                    List<Map<String, Object>> list2;
                                    List list3 = c.b(str);
                                    str = com.fuxi.cloud.desreport.b.c.a(str, (Map<String, Object>) null);
                                    if (StringUtils.isNotEmpty(jmReportDb.getDbSource())) {
                                        list2 = this.jmreportDynamicDbUtil.findList(jmReportDb.getDbSource(), str, new Object[0]);
                                    } else {
                                        list2 = this.reportDbDao.selectListBySql(str);
                                    }
                                    List<JmDictModel> list4 = a(jmReportDbField, list2);
                                    if (null != list4)
                                        queryVO.setDictList(list4);
                                }
                            }
                            arrayList.add(queryVO);
                        }
                    }
            }
            if (arrayList.size() > 0)
                for (QueryVO queryVO : arrayList) {
                    if (hashSet.contains(queryVO.getName()))
                        queryVO.setDuplicate(true);
                }
        }
        return arrayList;
    }

    @Override
    public List<JmDictModel> getDictListByCode(String dictCode, String username) {
        List<JmDictModel> list = null;
        if (dictCode.toLowerCase().indexOf("select") >= 0 && dictCode.toLowerCase().indexOf("from") >= 0) {
            list = this.reportDao.queryDictBySql(dictCode);
        } else {
            list = this.dictService.queryDictItemsByCode(dictCode, username);
        }
        return list;
    }

    @Override
    public JSONObject addChart(String chartType) {
        JSONObject jSONObject = null;
        try {
            String str1 = "static/jmreport/desreport_/chartjson/" + chartType + ".json";
            ClassPathResource classPathResource = new ClassPathResource(str1);
            byte[] arrayOfByte = FileCopyUtils.copyToByteArray(classPathResource.getInputStream());
            String str2 = new String(arrayOfByte);
            jSONObject = JSON.parseObject(str2);
        } catch (IOException iOException) {
            iOException.printStackTrace();
        }
        return jSONObject;
    }

    @Override
    public JimuReport excelCreate(JimuReport design) {
        Date date = new Date();
        design.setDelFlag(CommonConstant.DEL_FLAG_0);
        design.setUpdateTime(date);
        if (oConvertUtils.isNotEmpty(design.getId())) {
            design.setUpdateBy(design.getCreateBy());
            this.reportDao.update(design);
        } else {
            design.setCreateTime(date);
            this.reportDao.insert(design);
        }
        return design;
    }

    @Override
    public Result<JimuReport> show(String id, String params, String username) {
        JSONObject var4 = new JSONObject();
        if (ObjectUtil.isNotEmpty(params)) {
            var4 = JSON.parseObject(params);
        }

        boolean var5 = "1".equals(var4.getString("onlyPageData"));
        a.debug("============EXCEL JSON数据查询==========");
        JimuReport var6 = this.reportDao.get(id);
        String var7 = var6.getJsonStr();
        a.debug("====配置的json字符串===" + var6.getJsonStr());
        Map var8 = this.getDataById(id, var4, var5, username);
        var6.setDataList(var8);
        RenderInfo var9 = new RenderInfo(var6);
        var9.setStrategyName(b.class.getSimpleName());
        return this.a(var9);
    }

    private Result<JimuReport> a(RenderInfo paramRenderInfo) {
        if (ObjectUtil.isNotEmpty(this.renderHandlerMap))
            for (BaseRenderHandler baseRenderHandler : this.renderHandlerMap.values()) {
                if (baseRenderHandler.support(paramRenderInfo)) {
                    baseRenderHandler.beforeRender(paramRenderInfo);
                    Result<JimuReport> result = baseRenderHandler.render(paramRenderInfo);
                    if (ObjectUtil.isNotEmpty(result))
                        return result;
                    Result.OK(paramRenderInfo.getReport());
                }
            }
        return Result.OK(paramRenderInfo.getReport());
    }

    @Override
    public JimuReport saveReport(JSONObject json, HttpServletRequest request) {
        String var3 = this.jimuTokenClient.getUsername(request);
        a.debug("============EXCEL JSON数据正在保存==========");
        String var4 = json.getString("excel_config_id");
        JimuReport var5 = new JimuReport();
        if (oConvertUtils.isEmpty(var4)) {
            var5.setId(String.valueOf(SnowflakeIdWorker.generateId()));
            return var5;
        } else {
            var5 = this.reportDao.get(var4);
            JSONObject var6 = json.getJSONObject("designerObj");
            String var7 = "";
            String var8 = "";
            if (var6 != null) {
                var7 = var6.getString("name");
                var8 = var6.getString("type");
                json.remove("designerObj");
            }

            SimpleDateFormat var9 = new SimpleDateFormat("yyyyMMddHHmmss");
            String var10 = var9.format(new Date());
            if (var5 == null) {
                JimuReport var11 = new JimuReport();
                var11.setId(var4);
                var11.setCode(var10);
                var11.setDelFlag(CommonConstant.DEL_FLAG_0);
                var11.setTemplate(JmConst.TEMPLATE_FLAG_0);
                var11.setJsonStr(json.toJSONString());
                var11.setName(var7);
                var11.setType(var8);
                var11.setCreateBy(var3);
                Date var12 = new Date();
                var11.setCreateTime(var12);
                var11.setUpdateTime(var12);
                json.remove("excel_config_id");
                this.reportDao.insert(var11);
            } else {
                var5.setName(var7);
                var5.setType(var8);
                var5.setUpdateBy(var3);
                var5.setUpdateTime(new Date());
                var5.setJsonStr(json.toJSONString());
                this.reportDao.update(var5);
            }

            return var5;
        }
    }

    @Override
    public void replaceDbCode(String reportDbId, String username, List<Map<String, Object>> dataList) {
        if (ObjectUtil.isNotEmpty(reportDbId)) {
            List var4 = this.dbFieldDao.listByDbIdNotNull(reportDbId);
            Iterator var5 = var4.iterator();

            while(var5.hasNext()) {
                JmReportDbField var6 = (JmReportDbField)var5.next();
                List<JmDictModel> var7 = null;
                if (var6.getDictCode().contains("http")) {
                    var7 = this.a(var6);
                } else {
                    var7 = this.getDictListByCode(var6.getDictCode(), username);
                }

                Iterator var8 = dataList.iterator();

                while(var8.hasNext()) {
                    Map var9 = (Map)var8.next();
                    String var10 = Convert.toStr(var9.get(var6.getFieldName()));
                    Object var11 = new ArrayList();
                    if (ObjectUtil.isNotEmpty(var10)) {
                        var11 = (List)var7.stream().filter((var1) -> {
                            return var10.equals(var1.getValue());
                        }).collect(Collectors.toList());
                    }

                    if (((List)var11).size() > 0) {
                        var9.replace(var6.getFieldName(), ((JmDictModel)((List)var11).get(0)).getText());
                    }
                }
            }
        }

    }

    @Override
    public List<JimuReport> getReportByUser(String username, String reportId) {
        return this.reportDao.getReportByUser(username, reportId);
    }

    @Override
    public JSONObject getCharData(String reportId, String charId, String params, String token) {
        JSONObject jSONObject1 = new JSONObject();
        JimuReport jimuReport = this.reportDao.get(reportId);
        String str = jimuReport.getJsonStr();
        JSONObject jSONObject2 = JSONObject.parseObject(str);
        Object object = jSONObject2.get("chartList");
        JSONObject jSONObject3 = new JSONObject();
        if (null != object) {
            JSONArray jSONArray = JSONArray.parseArray(object.toString());
            for (byte b = 0; b < jSONArray.size(); b++) {
                Object object1 = jSONArray.getJSONObject(b).get("layer_id");
                if (null != object1 && charId.equals(object1.toString()))
                    jSONObject3 = jSONArray.getJSONObject(b);
            }
        }
        if (null != jSONObject3) {
            Object object1 = jSONObject3.get("config");
            Object object2 = jSONObject3.get("extData");
            jSONObject1.put("config", object1);
            jSONObject1.put("extData", object2);
            if (null != object2) {
                JSONObject jSONObject = JSONObject.parseObject(object2.toString());
                String str1 = String.valueOf(jSONObject.get("dbCode"));
                String str2 = a(reportId, str1, params, token);
                jSONObject1.put("dataList", str2);
                return jSONObject1;
            }
        }
        return null;
    }

    @Override
    public JimuReport getById(String id) {
        return this.reportDao.get(id);
    }

    @Override
    public Integer updateById(JimuReport rp) {
        return Integer.valueOf(this.reportDao.update(rp));
    }

    private String a(String paramString1, String paramString2, String paramString3, String paramString4) {
        JmReportDb jmReportDb = this.reportDbDao.getReportDb(paramString1, paramString2);
        JSONArray jSONArray = JSONArray.parseArray(paramString3);
        HashMap<String, Object> hashMap = new HashMap<>();
        JSONObject jSONObject1 = new JSONObject();
        for (Object object1 : jSONArray) {
            if (object1 instanceof JSONObject) {
                JSONObject jSONObject = JSONObject.parseObject(object1.toString());
                Iterator<String> iterator = jSONObject.keySet().iterator();
                while (iterator.hasNext()) {
                    String str1 = iterator.next();
                    String str2 = jSONObject.getString(str1);
                    hashMap.put(str1, str2);
                    jSONObject1.put(str1, str2);
                }
            }
        }
        if (jmReportDb.getDbType().equals("0")) {
            String str1 = jmReportDb.getDbDynSql();
            String str2 = getBaseSql(jmReportDb.getId(), jmReportDb.getDbDynSql(), jSONObject1);
            if (oConvertUtils.isNotEmpty(jmReportDb.getDbSource())) {
                List<Map<String, Object>> list1 = this.jmreportDynamicDbUtil.findList(jmReportDb.getDbSource(), str2, new Object[0]);
                return a(list1);
            }
            List<Map<String, Object>> list = this.reportDbDao.selectListBySql(str2);
            return a(list);
        }
        JSONObject jSONObject2 = new JSONObject();
        String str = jmReportDb.getApiUrl();
        str = FreeMarkerUtils.a(str, hashMap);
        str = str.replace("'", "");
        jmReportDb.setApiUrl(str);
        Map map = a(jmReportDb, paramString4, jSONObject2);
        Object object = map.get("dataList");
        if (ObjectUtils.isNotEmpty(object))
            return String.valueOf(object);
        return null;
    }

    private void a(JmReportDb paramJmReportDb, String paramString1, String paramString2, List<JmExpression> paramList) {
        for (JmExpression jmExpression : paramList) {
            if (paramJmReportDb.getDbCode().equals(jmExpression.getDbCode())) {
                String str = jmExpression.getFullSql(paramString1, paramString2);
                if (oConvertUtils.isEmpty(paramJmReportDb.getDbSource())) {
                    JmExpBacker jmExpBacker = this.reportDao.queryExpValue(str);
                    jmExpression.setValue((jmExpBacker == null) ? "" : jmExpBacker.getAskey());
                    continue;
                }
                Map map = (Map)this.jmreportDynamicDbUtil.findOne(paramJmReportDb.getDbSource(), str, new Object[0]);
                jmExpression.setValue((map.get("askey") == null) ? "" : map.get("askey").toString());
            }
        }
    }

    private String a(String paramString1, String paramString2, String paramString3) {
        if (paramString2 != null && !"".equals(paramString2))
            paramString1 = "select * from (" + paramString1 + ") jeecg_rp_temp  where 1=1 " + paramString2;
        if (ObjectUtil.isNotEmpty(paramString3)) {
            String str = "order by";
            if (!paramString1.contains(str)) {
                paramString1 = paramString1 + " " + str + " " + paramString3;
            } else {
                String str1 = paramString1.substring(paramString1.indexOf(str) + str.length());
                str1 = str1 + "," + paramString3;
                paramString1 = paramString1.substring(0, paramString1.indexOf(" " + str + " ")) + " " + str + " " + str1;
            }
        }
        return paramString1;
    }

    private String a(JmReportDb paramJmReportDb, JSONObject paramJSONObject) {
        String str1 = paramJmReportDb.getDbCode();
        String str2 = paramJmReportDb.getDbSourceType();
        List<JmReportDbField> list = this.dbFieldDao.listByDbIdFlag(paramJmReportDb.getId());
        String str3 = null;
        if (list != null && list.size() > 0) {
            StringBuffer stringBuffer = new StringBuffer();
            for (JmReportDbField jmReportDbField : list) {
                c.a(str1, str2, jmReportDbField, paramJSONObject, stringBuffer);
            }
            str3 = stringBuffer.toString();
        }
        return str3;
    }

    @Override
    public String getBaseSql(String dbId, String sql, JSONObject paramJson) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        JSONObject jSONObject = new JSONObject();
        Set set = paramJson.keySet();
        if (sql.contains("where")) {
            List<JmReportDbParam> list = this.dbParamDao.list(dbId);
            if (list != null || list.size() > 0)
                for (JmReportDbParam jmReportDbParam : list) {
                    String str1 = jmReportDbParam.getParamName();
                    if (set.contains(str1))
                        continue;
                    jSONObject.put(str1, jmReportDbParam.getParamValue());
                }
        }
        jSONObject.putAll((Map)paramJson);
        for (String str1 : jSONObject.keySet()) {
            String str2 = jSONObject.getString(str1);
            if (ObjectUtil.isEmpty(str2))
                str2 = "";
            sql = sql.replace("${" + str1 + "}", str2);
        }
        String str = paramJson.getString("X-Access-Token");
        if (str != null && str.length() > 0) {
            Map map = this.jimuTokenClient.getUserInfo(str);
            sql = c.b(sql, map);
        }
        return sql;
    }

    @Override
    public Result<JmPage<JimuReport>> excelQuery(String type, String name, HttpServletRequest request, Integer pageNo, Integer pageSize) {
        String str = this.jimuTokenClient.getUsername(request);
        JimuReport jimuReport = new JimuReport();
        if (StringUtils.isNotEmpty(str))
            jimuReport.setCreateBy(str);
        if (StringUtils.isNotEmpty(type))
            jimuReport.setType(type);
        if (StringUtils.isNotEmpty(name))
            jimuReport.setName(name);
        jimuReport.setDelFlag(CommonConstant.DEL_FLAG_0);
        jimuReport.setTemplate(JmConst.TEMPLATE_FLAG_0);
        MiniDaoPage miniDaoPage = this.reportDao.pageList(jimuReport, pageNo.intValue(), pageSize.intValue());
        JmPage jmPage = com.fuxi.cloud.desreport.b.b.a(miniDaoPage);
        return Result.OK(jmPage);
    }

    @Override
    public Result<JmPage<JimuReport>> excelQueryByTemplate(String type, String name, HttpServletRequest request, Integer pageNo, Integer pageSize) {
        JimuReport jimuReport = new JimuReport();
        if (StringUtils.isNotEmpty(type))
            jimuReport.setType(type);
        if (StringUtils.isNotEmpty(name))
            jimuReport.setName(name);
        jimuReport.setDelFlag(CommonConstant.DEL_FLAG_0);
        jimuReport.setTemplate(JmConst.TEMPLATE_FLAG_1);
        MiniDaoPage miniDaoPage = this.reportDao.pageList(jimuReport, pageNo.intValue(), pageSize.intValue());
        JmPage jmPage = com.fuxi.cloud.desreport.b.b.a(miniDaoPage);
        return Result.OK(jmPage);
    }

    public List<JmDictModel> a(JmReportDbField paramJmReportDbField) {
        String str1 = paramJmReportDbField.getDictCode();
        str1 = str1 + "?" + "dictCode" + "=" + paramJmReportDbField.getFieldName();
        String str2 = c.b(str1, (Map<String, Object>) null);
        try {
            JSONArray jSONArray = JSONObject.parseArray(str2);
            ArrayList<JmDictModel> arrayList = new ArrayList();
            for (byte b = 0; b < jSONArray.size(); b++) {
                JSONObject jSONObject = jSONArray.getJSONObject(b);
                Object object1 = jSONObject.get("text");
                Object object2 = jSONObject.get("value");
                if (ObjectUtil.isEmpty(object1) || ObjectUtil.isEmpty(object2))
                    return null;
                JmDictModel jmDictModel = new JmDictModel();
                jmDictModel.setText(object1.toString());
                jmDictModel.setValue(object2.toString());
                arrayList.add(jmDictModel);
            }
            return arrayList;
        } catch (Exception exception) {
            return null;
        }
    }

    public List<JmDictModel> a(JmReportDbField var1, List<Map<String, Object>> var2) {
        Integer var3 = var1.getSearchFlag();
        Integer var4 = var1.getSearchMode();
        String var5 = var1.getFieldName();
        if (var3.equals(CommonConstant.SEARCH_FLAG_1) && !var4.equals(CommonConstant.SEARCH_MODEL_2)) {
            ArrayList<JmDictModel> var6 = new ArrayList();
            Iterator var7 = var2.iterator();

            while(var7.hasNext()) {
                Map var8 = (Map)var7.next();
                Iterator var9 = var8.keySet().iterator();

                while(var9.hasNext()) {
                    String var10 = (String)var9.next();
                    if (var10.toLowerCase().equals(var5)) {
                        String var11 = String.valueOf(var8.get(var10));
                        boolean var12 = var6.stream().anyMatch((var1x) -> {
                            return var1x.getText().equals(var11);
                        });
                        if (!var12 && oConvertUtils.isNotEmpty(var11)) {
                            JmDictModel var13 = new JmDictModel();
                            var13.setText(var11);
                            var13.setValue(var11);
                            var6.add(var13);
                        }
                    }
                }
            }

            return var6;
        } else {
            return null;
        }
    }

    public String a(List<Map<String, Object>> paramList) {
        ArrayList<String> arrayList = new ArrayList();
        for (Map<String, Object> map : paramList) {
            String str = JSONObject.toJSONString(map);
            arrayList.add(str.toLowerCase());
        }
        if (arrayList.size() > 0)
            return arrayList.toString();
        return null;
    }

    private ReportDbInfo a(JmReportDb paramJmReportDb, JSONObject paramJSONObject, String paramString) {
        ReportDbInfo reportDbInfo = new ReportDbInfo(paramJmReportDb.getIsPage(), paramJmReportDb.getIsList(), paramJmReportDb.getDbType());
        String str1 = paramJmReportDb.getDbCode();
        HashMap<String, Object> hashMap = new HashMap<>();
        List<JmReportDbParam> list = this.dbParamDao.list(paramJmReportDb.getId());
        ArrayList<String> arrayList = new ArrayList();
        arrayList.add("pageNo");
        arrayList.add("pageSize");
        arrayList.add("printAll");
        if (c.a(list))
            for (JmReportDbParam jmReportDbParam : list) {
                arrayList.add(jmReportDbParam.getParamName());
                String str = jmReportDbParam.getParamValue();
                if (str != null && !"".equals(str))
                    hashMap.put(jmReportDbParam.getParamName(), str);
            }
        Iterator<String> iterator = paramJSONObject.keySet().iterator();
        while (iterator.hasNext()) {
            String str = iterator.next();
            Object object = paramJSONObject.get(str);
            if (object != null) {
                if (str.startsWith(str1)) {
                    str = str.replace(str1 + "__", "");
                    hashMap.put(str, object);
                    continue;
                }
                if (arrayList.indexOf(str) >= 0)
                    hashMap.put(str, object);
            }
        }
        String str2 = paramJmReportDb.getJavaType();
        String str3 = paramJmReportDb.getJavaValue();
        IDataSetFactory iDataSetFactory = c.d(str2, str3);
        if (iDataSetFactory == null)
            return reportDbInfo;
        if ("1".equals(paramJmReportDb.getIsPage())) {
            JmPage jmPage = iDataSetFactory.createPageData(hashMap);
            reportDbInfo.setList(jmPage.getRecords());
            reportDbInfo.setTotal(jmPage.getTotal());
        } else {
            List list1 = iDataSetFactory.createData(hashMap);
            reportDbInfo.setList(list1);
        }
        if (null != reportDbInfo.getList()) {
            List<Map<String, Object>> list1 = reportDbInfo.getList();
            replaceDbCode(paramJmReportDb.getId(), paramString, list1);
            reportDbInfo.setList(list1);
        }
        return reportDbInfo;
    }
}
